package com.lecampus.businessSecond_hand_transactions.controller;


import com.lecampus.businessSecond_hand_transactions.entity.ProductComment;
import com.lecampus.businessSecond_hand_transactions.service.ProductCommentService;
import com.lecampus.businessSecond_hand_transactions.vo.ProductCommentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-03-24
 */
@RestController
@RequestMapping("lecampus/product")
public class ProductCommentController {
    @Autowired
    private ProductCommentService productCommentService;

    @GetMapping("/{productId}/comments/currentPage={currentPage}&size={size}")
    public List<ProductCommentVO> findAllComments(@PathVariable("productId") String productId,
                                                  @PathVariable("currentPage") long currentPage,
                                                  @PathVariable("size") long size) {
        return productCommentService.findCommentsByProductId(productId,currentPage,size);
    }

    @PostMapping("/{productId}/input-comment")
    public void inputComment(@PathVariable("productId") String productId,
                             ProductComment comment) {
        productCommentService.inputComment(productId,comment);
    }

    @GetMapping("/{productId}/comment/{commentId}/delete")
    public void deleteComment(@PathVariable("productId") String productId,
                              @PathVariable("commentId") String commentId) {
        productCommentService.deleteByCommentId(productId,commentId);
    }

    @GetMapping("/comment/{productCommentId}/like/flag={flag}")
    public void likes(@PathVariable("productCommentId") String productCommentId,
                      @PathVariable("flag") int flag) {
        productCommentService.likes(productCommentId,flag);
    }
}

